import android
import time
import urllib2
import simplejson
import zlib


#Personalization Items
site = 'stackoverflow'
usrid = '68172'
timeframe = (60*60)
#End Personalization Items

apiver = '1.0'
fromdate = int(time.time() - timeframe)

droid = android.Android()
droid.makeToast('checking ' + site)

url = "http://api."+site+".com/"+apiver+"/users/"+usrid+"/reputation?fromdate="+str(fromdate)

requestData = zlib.decompress(urllib2.urlopen(url).read(),16+zlib.MAX_WBITS)
repdata = simplejson.load(requestData)[u'rep_changes']

reppos = 0
repneg = 0

for reps in repdata:
   reppos += int(reps[u'positive_rep'])
   repneg += int(reps[u'negative_rep'])

if reppos > 0 or repneg > 0:
   droid.notify('message', 'StackOverflow Rep changed', str(reppos)+' rep gained ' + str(repneg)+ ' rep lost.')
else:
   droid.exit()
